package com.itheima.lambda;

import java.util.Random;

public class Test4 {

    /*

     */

    public static void main(String[] args) {
    //接口类型 变量名 =实现类对象
    //接口多态
        RandomNumHandler number=new RandomNumHandler() {
            @Override
            public int getNumber() {
                Random r=new Random();
                int num=r.nextInt(31)+20;//20~50
                return num;
            }
        };
        int num=number.getNumber();
        System.out.println("num"+num);

        System.out.println("-----------");

        RandomNumHandler number1=()->{
            Random r=new Random();
            int res=r.nextInt(31)+20;
            return res;
        };
        int num1=number1.getNumber();
        System.out.println("num1="+num1);
    }

}
//1.定义接口
interface RandomNumHandler{
    int getNumber();
}